package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28956
 * Date: 2024-01-27
 * Time: 22:46
 */
public class FindOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书！");
        System.out.println("请输入你要查找的图书名字：");
        //输入书名
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        //遍历数组
        int currentSize = bookList.getUsedSize();//获取当前有几本书
        for (int i = 0; i <currentSize ; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("找到了这本书，信息如下：");
                System.out.println(book);
                return;
            }
        }
        System.out.println("很抱歉，没有找到这本书！");
    }
}
